﻿/****************************** Module Header ******************************\
 * Module Name:  CMSTextBox.cs
 * Module Version:  1.0.0 (2012-10-26)
 * Copyright (c) AnyEB.Com (14507247@qq.com)
 * 
 * This class is used to process the CheckedListBox.
 * 
 * This source is subject to the GPL License.
 * See http://www.gnu.org/licenses/gpl.html.
 * All other rights reserved.
 * 
 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/
using System;
using System.Windows.Forms;

namespace UCF.Core.Forms.CustomControls
{
    /// <summary>
    /// 基本右键菜单
    /// </summary>
    public class SoCMSCheckedListBox : ContextMenuStrip
    {
        /// <summary>
        /// 全选按钮
        /// </summary>
        private ToolStripMenuItem miCheckAll = new ToolStripMenuItem("全选");

        /// <summary>
        /// 反选按钮
        /// </summary>
        private ToolStripMenuItem miCheckInverse = new ToolStripMenuItem("反选");

        /// <summary>
        /// 重置按钮
        /// </summary>
        private ToolStripMenuItem miReset = new ToolStripMenuItem("重置");

        public SoCMSCheckedListBox(params CheckedListBox[] boxes)
        {
            this.miCheckAll.Click+=new EventHandler(miCheckAll_Click);
            this.miCheckInverse.Click += new EventHandler(miCheckInverse_Click);
            this.miReset.Click += new EventHandler(miReset_Click);
            this.Items.Add(miCheckAll);
            this.Items.Add(miReset);
            this.Items.Add(miCheckInverse);
            foreach (CheckedListBox tb in boxes)
            {
                tb.ContextMenuStrip = this;
            }
        }
        protected void miReset_Click(object s, EventArgs e)
        {
            ((CheckedListBox)this.SourceControl).SetItemsChecked(false);
        }
        protected void miCheckInverse_Click(object s, EventArgs e)
        {
            ((CheckedListBox)this.SourceControl).SetItemsInverseChecked();
        }
        protected void miCheckAll_Click(object s, EventArgs e)
        {
            ((CheckedListBox)this.SourceControl).SetItemsChecked(true);
        }
    }
}
